package com.panopset.io;

import java.io.File;
import java.util.List;

/**
 * File backed list.
 * @author Karl Dinwiddie
 *
 */
public final class FileList {

    /**
     * List.
     */
    private final List<String> list;

    /**
     * File.
     */
    private final File f;

    /**
     *
     * @return File.
     */
    public File getFile() {
        return f;
    }
    /**
     *
     * @param file File.
     */
    public FileList(final File file) {
        f = file;
        if (!new Filez().isAvailable(file)) {
            throw new RuntimeException(new Filez().getCanonicalPath(file));
        }
        list = new Filez().loadLines(f);
    }

    /**
     * @return File backed list of new Stringz().
     */
    public List<String> getList() {
        return list;
    }
    /**
     * Save list to file.
     */
    public void flush() {
        new Filez().saveLines(f, list);
    }
}
